package cn.wolfcode.trip.base.domain;


import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 攻略分类
 */
@Getter
@Setter
//懒加载动态代理引入handler属性,转换成json会报错
//JsonIGnoreProperties 可以在json时忽略转换指定属性
@JsonIgnoreProperties("handler")
public class StrategyCatalog {

    public static final Boolean STATE_NORMAL = true;   //启用状态
    public static final Boolean STATE_DISABLE = false; //禁用状态\

    private Long id;

    //攻略分类名称
    private String name;
    //攻略分类所属大攻略
    private Strategy strategy;
    //攻略分类序号
    private Integer sequence;
    //攻略分类状态
    private Boolean state = STATE_NORMAL; //默认为启用状态

    private List<StrategyDetail> detailList = new ArrayList<>();


    public String getStateDisplay() {
        if (state == STATE_NORMAL) {
            return "启动";
        } else if (state == STATE_DISABLE) {
            return "禁用";
        }
        return "";
    }

    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        if (strategy != null) {
            map.put("strategyId", strategy.getId());
        }
        map.put("sequence", sequence);
        map.put("state", state);
        return JSONUtil.toJsonString(map);
    }
}